package com.asset.dispoal.department;

import com.asset.dispoal.department.api.SysDepartmentQueryService;
import com.asset.dispoal.department.api.SysDepartmentService;
import com.asset.dispoal.department.dto.DepartmentRequest;
import com.asset.dispoal.department.dto.DepartmentResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.mhuang.pacebox.springboot.core.controller.BaseController;
import tech.mhuang.pacebox.springboot.core.permission.annotation.Permission;
import tech.mhuang.pacebox.springboot.protocol.Result;

import java.util.List;

/**
 * @author qr
 * @date 2022/2/15$
 */
@RestController
@Api(value = "部门管理", tags = "部门管理")
@RequestMapping("system/department")
public class DepartmentController extends BaseController {

    @Autowired
    SysDepartmentQueryService queryService;

    @Autowired
    SysDepartmentService departmentService;

    @Permission(code = "systemSection:add")
    @PostMapping("insert")
    @ApiOperation(value = "添加", notes = "添加")
    public Result insert(@RequestBody DepartmentRequest request) {
        departmentService.insert(request);
        return Result.ok();
    }

    @Permission(code = "systemSection:update")
    @PostMapping("update")
    @ApiOperation(value = "修改", notes = "修改")
    public Result update(@RequestBody DepartmentRequest request) {
        departmentService.update(request);
        return Result.ok();
    }

    @Permission(code = "systemSection:del")
    @PostMapping("delete")
    @ApiOperation(value = "删除", notes = "删除")
    public Result delete(@RequestBody DepartmentRequest request) {
        departmentService.delete(request);
        return Result.ok();
    }


    @Permission(code = "systemSection:query")
    @GetMapping("queryDepartment")
    @ApiOperation(value = "查询分页", notes = "查询分页")
    public Result<List<DepartmentResponse>> queryDepartment(DepartmentRequest request) {
        return queryService.queryDepartment(request);
    }


}
